﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GenUtil.Dto;
using GenUtil.Util;
using DataLayer.Dao.Sql;
using System.Data;


namespace ServiceLayer.Service.Impl
{
    public class StudentServiceImpl : StudentService
    {
        Logger logger = new Logger(typeof(StudentServiceImpl));
        public void InsertStudentDto(StudentDto studentDto)
        {
            logger.debug("Entering CustomerServiceImpl.InsertCustomerDto()");
            try
            {
                int maxStudentId = DaoFactory.getStudentDao().getMaxStudentId();
                studentDto.StudentId = maxStudentId + 1;
                studentDto.LastUpdDts = DateTime.Now;
                studentDto.LastupdUserId = "Koushik Ghosh";
                DaoFactory.getStudentDao().InsertStudentDto(studentDto);
            }
            catch (Exception e)
            {
                logger.fatal("Exception in StudentServiceImpl.InsertStudentDto():" + e.Message, e);
                throw new Exception("Exception in StudentServiceImpl.InsertStudentDto():" + e.Message, e);
            }
            logger.debug("Exiting StudentServiceImpl.InsertStudentDto()");
        }
        public StudentDto getStudentDto(int StudentId)
        {
            logger.debug("Entering StudentServiceImpl.getStudentDto()");
            StudentDto studentDto = null;
            try
            {
                studentDto = DaoFactory.getStudentDao().getStudentDto(StudentId);
            }
            catch (Exception e)
            {
                logger.fatal("Exception in StudentServiceImpl.getStudentDto():" + e.Message, e);
                throw new Exception("Exception in StudentServiceImpl.getStudentDto():" + e.Message, e);
            }
            logger.debug("Exiting StudentServiceImpl.getStudentDto()");
            return studentDto;
        }
        public List<StudentDto> getStudentDtos()
        {
            logger.debug("Entering StudentDaoSql.getStudentDtos()");
            List<StudentDto> studentDtos = null;
            try
            {
               studentDtos = DaoFactory.getStudentDao().getStudentDtos();
            }
            catch (Exception e)
            {
                logger.fatal("Exception in StudentServiceImpl.getStudentDtos():" + e.Message, e);
                throw new Exception("Exception in StudentServiceImpl.getStudentDtos():" + e.Message, e);
            }
            logger.debug("Exiting StudentServiceImpl.getStudentDtos()");
            return studentDtos;
        }
        public StudentDto getStudentRecord(string rollNo)
        {
            logger.debug("Entering StudentServiceImpl.getStudentRecord()");
            StudentDto studentDto = null;
            try
            {
                studentDto = DaoFactory.getStudentDao().getStudentRecord(rollNo);
            }
            catch (Exception e)
            {
                logger.fatal("Exception in StudentServiceImpl.getStudentRecord():" + e.Message, e);
                throw new Exception("Exception in StudentServiceImpl.getStudentRecord():" + e.Message, e);
            }
            logger.debug("Exiting StudentServiceImpl.getStudentRecord()");
            return studentDto;
        }
        public StudentDto getStudentEmailId(string emailId)
        {
            logger.debug("Entering StudentServiceImpl.getStudentEmailId()");
            StudentDto studentDto = null;
            try
            {
                studentDto = DaoFactory.getStudentDao().getStudentEmailId(emailId);
            }
            catch (Exception e)
            {
                logger.fatal("Exception in StudentServiceImpl.getStudentEmailId():" + e.Message, e);
                throw new Exception("Exception in StudentServiceImpl.getStudentEmailId():" + e.Message, e);
            }
            logger.debug("Exiting StudentServiceImpl.getStudentEmailId()");
            return studentDto;
        }
        public DataSet getDataSet()
        {
            logger.debug("Entering StudentServiceImpl.getDataSet()");
            DataSet ds = null;
            try
            {
                ds = DaoFactory.getStudentDao().getDataSet();
            }
            catch (Exception e)
            {
                logger.fatal("Exception in StudentServiceImpl.getDataSet():" + e.Message, e);
                throw new Exception("Exception in StudentServiceImpl.getDataSet():" + e.Message, e);
            }
            logger.debug("Exiting StudentServiceImpl.getDataSet()");
            return ds;
        }
    }
}
